package com.smmisia.auth.controller;

import com.smmisia.auth.mapper.UserMapper;
import com.smmisia.auth.utls.EasyExcelUtil;
import com.smmisia.common.entity.auth.User;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Tag(name = "excel")
@RequestMapping("/excel")
@RestController
@Slf4j
public class ExcelController {

    @Autowired
    private UserMapper userMapper;


    @Operation(summary = "导出用户数据")
    @GetMapping("/export")
    public void export(HttpServletResponse response) {

        List<User> user = userMapper.selectList(null);

        List<UserData> userData = UserConvertor.INSTANCE.mapToUserDataList(user);

        EasyExcelUtil.export(response, "用户数据", "用户数据",userData, UserData.class);


    }
}


